package com.atguigu.exception;

import com.atguigu.pojo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice("com.atguigu.controller")
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exception(Exception e) {
        e.printStackTrace();
        return Result.error();
    }
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Result exception(CustomException e) {
//        e.printStackTrace();
        Result error = Result.error(e.getCode(), e.getMsg());
        System.out.println(error);
        return error;
    }

}
